#include<iostream>
using namespace std;

typedef long long ll;


ll pow(ll a, ll b, ll p)
{
	ll ret=1;
	while(b)
	{
		if(b&1) ret=ret*a%p;
		a=a*a%p;
		b>>=1;
	}
	return ret;
}
int main()
{
	ll a, b, p; cin>>a>>b>>p;
	printf("%lld^%lld mod %lld=%lld", a, b, p, pow(a, b, p));
	return 0;
}
